package com.kingtown.inventory.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.kingtown.inventory.R;
import com.kingtown.inventory.domain.dto.KiFloor;
import com.kingtown.inventory.domain.dto.KiPosition;

import java.util.List;

public class PositionAdapter extends BaseAdapter {
    private Context context;
    private List<KiPosition> mData;

    public PositionAdapter(Context context, List<KiPosition> mData) {
        this.context = context;
        this.mData = mData;
    }

    @Override
    public int getCount() {
        return mData != null ? mData.size() : 0;
    }

    @Override
    public Object getItem(int i) {
        return mData.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder = null;
        if (view == null) {
            holder = new ViewHolder();
            view = LayoutInflater.from(context).inflate(R.layout.spinner_item
                    , viewGroup
                    , false);
            holder.name = (TextView) view.findViewById(R.id.txt_item_name);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        holder.name.setText(mData.get(i).getPosition());
        return view;
    }

    static class ViewHolder {
        private TextView name;
    }
}
